package com.yyc.system.controller;
import com.yyc.core.Result;
import com.yyc.core.ResultGenerator;
import com.yyc.system.model.TCourseClassTeacher;
import com.yyc.system.model.TCourseUser;
import com.yyc.system.service.ITCourseClassTeacherService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
* Created by yyc on 2019/01/06.
*/
@RestController
@RequestMapping("/t/course/class/teacher")
public class TCourseClassTeacherController {
    @Autowired
    private ITCourseClassTeacherService tCourseClassTeacherService;

    @RequestMapping("/add")
    public Result add(@RequestBody TCourseClassTeacher tCourseClassTeacher) {
        tCourseClassTeacherService.save(tCourseClassTeacher);
        return ResultGenerator.genSuccessResult();
    }

    @RequestMapping("/delete")
    public Result delete(@RequestParam String ids) {
        tCourseClassTeacherService.deleteByIds(ids);
        return ResultGenerator.genSuccessResult();
    }

    @RequestMapping("/update")
    public Result update(@RequestBody TCourseClassTeacher tCourseClassTeacher) {
        tCourseClassTeacherService.update(tCourseClassTeacher);
        return ResultGenerator.genSuccessResult();
    }

    @RequestMapping("/detail")
    public Result detail(@RequestParam Integer id) {
        TCourseClassTeacher tCourseClassTeacher = tCourseClassTeacherService.findById(id);
        return ResultGenerator.genSuccessResult(tCourseClassTeacher);
    }

    @RequestMapping("/list")
    public Result list(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "0") Integer size) {
    	PageHelper.startPage(page, size);
        List<TCourseClassTeacher> list = tCourseClassTeacherService.queryCourseMessage();
        PageInfo<TCourseClassTeacher> pageInfo = new PageInfo<TCourseClassTeacher>(list);
        return ResultGenerator.genSuccessResult(pageInfo);
    }
    
    //***********************************************************************
    @RequestMapping("/queryCourseMessage")
    public Result queryCourseMessage(Integer classId,Integer userId){
    	List<TCourseClassTeacher> list = tCourseClassTeacherService.findCourseMessage(classId,userId);
    	return ResultGenerator.genSuccessResult(list);
    }

}
